package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Invoice;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.InvoiceService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(value = "发票",tags ="发票接口API" )
public class AllInvoiceController {
@Autowired
    private InvoiceService invoiceService;
    @RequestMapping(value = "/selectInvoiceAll",method = RequestMethod.POST)
    @ApiOperation(value = "查询所有发票接口",notes = "业务员管理员查询",httpMethod = "POST",response = ResultJson.class)
   @ApiImplicitParams({
           @ApiImplicitParam(name = "invoice_number",value = "发票收据编号",paramType =  "query",dataType = "invoice",required = false),
           @ApiImplicitParam(name = "order_id",value = "订单编号",paramType =  "query",dataType = "invoice",required = false)
   })
    public ResultJson selectInvoiceAll(@RequestBody
      @ApiParam(name="map",value = "{invoice_id 发票编号(int)," +
              "invoice_number 发票收据编号(String)," +
              "commodity_money 商品金额(double)," +
              "create_id 创建人id(int)," +
              "creation_time 创建时间(date)," +
              "invoice_basis 发票依据(String)," +
              "}") Map map){
        return  invoiceService.selectinvoiceAll(map);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/addInvoice",method = RequestMethod.POST)
    @ApiOperation(value = "新增发票接口",notes = "管理员新增",httpMethod = "POST",response = ResultJson.class)
   @ApiImplicitParam(name="invoice_number",value = "发表收据编号",required = false,dataType = "invoice",paramType = "query")
    public ResultJson addInvoice(@RequestBody @ApiParam(name = "invoice",value = "新增发票") Invoice invoice){
       // Login login = (Login) SecurityUtils.getSubject().getPrincipal();
       Login login = new Login();
       login.setUser_id(1);
        System.out.println(login);
        System.out.println("************************");
        System.out.println(invoice.getInvoice_number());
        System.out.println(invoice.getCreate_id());
        System.out.println("修改发票");
        System.out.println("*****************");

        return invoiceService.addInvoice(invoice,login);
    }

    @RequestMapping(value = "/updateInvoice",method = RequestMethod.POST)
    @ApiOperation(value = "修改发票接口",notes = "管理员新增",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "发票编号",required = false,dataType = "invoice",paramType = "query")
    public  ResultJson updateInvoice(@ApiParam(name = "invoice",value = "修改发票") Integer id){
        return invoiceService.updateInvoice(id);
    }

    /**
     * 根据id删除
     * @return
     */
    @RequestMapping(value = "/deleteInvoice",method = RequestMethod.POST)
    @ApiOperation(value = "删除发票接口",notes = "管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name="id",value = "发票编号",required = false,dataType = "invoice",paramType = "query")
    public ResultJson deleteInvoice(@ApiParam(name = "invoice",value = "删除发票") Integer id){
        return invoiceService.deleteByIdInvoice(id);
    }
}
